home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / Kibitz / PPCBrowserOverride.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  7.0 KB  |  242 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        ppcbrowseroverride.c
  5. ** Written by:  C.K. Haun
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __CONTROLS__
  21. #include <Controls.h>
  22. #endif
  23.  
  24. #ifndef __OSEVENTS__
  25. #include <OSEvents.h>
  26. #endif
  27.  
  28. #ifndef __TRAPS__
  29. #include <Traps.h>
  30. #endif
  31.  
  32.  
  33.  
  34. /*****************************************************************************/
  35. /*****************************************************************************/
  36.  
  37. #ifdef applec
  38. #pragma segment appStart
  39. #endif
  40.  
  41. /*****************************************************************************/
  42. /*****************************************************************************/
  43.  
  44.  
  45.  
  46. /* Thanks to C.K. for his Hack-To-Go service here in DTS.  Just leave a message,
  47. ** and the hack will show up via QuickMail really soon.  This is really interesting,
  48. ** since I've seen him type.  I don't know how he gets them done so fast.
  49. ** My only figuring is that he doesn't waste too much time with the space or tab keys
  50. ** on his keyboard.  (I added the spaces and tabs.) */
  51.  
  52. /* Theory of hack:
  53. ** Lots of zones (which describes Apple) is a real pain to browse looking for a game
  54. ** of chess.  This hack allows a really slimy way of coercing PPCBrowser to scan the
  55. ** zones until it finds a zone that has a machine running Kibitz.  Since we figure
  56. ** that this need doesn't apply to many companies (how many companies have hundreds
  57. ** of zones?), there really isn't much need to spend too much time polishing this
  58. ** “feature”.
  59. **
  60. ** Since it is a really slimy hack, it was implemented into Kibitz as a hiddel feature.
  61. ** If you hold down the shift key when you do the menu command to connect to another
  62. ** player, then you have this auto-scan-of-zones feature active.  If the feature is
  63. ** active, then if you are displaying a zone that has no machine running Kibitz, after
  64. ** a maximum of 10 seconds, the patch posts a down-arrow.  The down arrow moves the
  65. ** zone list to the next available zone, assuming that the zone list is the active
  66. ** list.
  67. **
  68. ** Of course, if the zone list isn't the active zone, this feature isn't too useful.
  69. ** This is why it is a hack.  It does the job, if you know what you are doing.
  70. **
  71. ** It actually works reasonably well, as it beats the heck of choosing on the next
  72. ** zone by hand to see if anybody's running Kibitz in that zone.
  73. */
  74.  
  75.  
  76.  
  77. typedef struct myParamBlock {
  78.     short                activeFlag;
  79.     short                dialogUp;
  80.     short                scrollActive;
  81.     long                tickCounter;
  82.     UniversalProcPtr    oldGND;
  83.     UniversalProcPtr    oldMD;
  84.     UniversalProcPtr    oldDD;
  85.     long                oldFilter;
  86. } myParamBlock;
  87. myParamBlock OurParamBlock;
  88.  
  89. /* this define contains the ASCII and the keycode, in case anyone cares */
  90. /* This is, by the way, for a US keyboard in US script.  Your script may */
  91. /* vary, please check your owners manual */
  92.  
  93. #define kDownArrowKey 0x27D1F
  94. #define kFiveSeconds 300
  95.  
  96. extern void        GNDPatch(void);  /* the actual paramter passing doesn't matter here */
  97. extern void        MDPatch(void);
  98. extern void        DDPatch(void);
  99.  
  100. void            TogglePPCPatches(Boolean on);
  101. Boolean            CheckMachineList(void);
  102. void            DoModalFilter(void);
  103. ControlHandle    FindSB(WindowPtr theWindow);
  104.  
  105.  
  106.  
  107. /*****************************************************************************/
  108.  
  109.  
  110.  
  111. void    TogglePPCPatches(Boolean on) {
  112. #ifndef __MWERKS__
  113. #pragma unused (on)
  114. #endif
  115.  
  116. #ifndef __MWERKS__
  117. #ifndef powerc
  118.  
  119.     if (on) {        /* turn everything on */
  120.         OurParamBlock.activeFlag   = true;
  121.         OurParamBlock.dialogUp     = false;
  122.         OurParamBlock.scrollActive = false;
  123.         OurParamBlock.tickCounter  = 0;
  124.         OurParamBlock.oldGND       = NGetTrapAddress(_GetNewDialog,ToolTrap);
  125.         OurParamBlock.oldMD        = NGetTrapAddress(_ModalDialog,ToolTrap);
  126.         OurParamBlock.oldDD        = NGetTrapAddress(_DisposDialog,ToolTrap);
  127.  
  128.         /* and set them to what we want please */
  129.  
  130.         NSetTrapAddress((UniversalProcPtr)GNDPatch,_GetNewDialog,ToolTrap);
  131.         NSetTrapAddress((UniversalProcPtr)MDPatch,_ModalDialog,ToolTrap);
  132.         NSetTrapAddress((UniversalProcPtr)DDPatch,_DisposDialog,ToolTrap);
  133.     }
  134.     else {        /* turning off.  Kill ebbybiddy */
  135.         OurParamBlock.activeFlag   = false;
  136.         OurParamBlock.dialogUp     = false;
  137.         OurParamBlock.scrollActive = false;
  138.         OurParamBlock.tickCounter  = 0;
  139.  
  140.         /* revert the routines */
  141.  
  142.         NSetTrapAddress(OurParamBlock.oldGND,_GetNewDialog,ToolTrap);
  143.         NSetTrapAddress(OurParamBlock.oldMD,_ModalDialog,ToolTrap);
  144.         NSetTrapAddress(OurParamBlock.oldDD,_DisposDialog,ToolTrap);
  145.     }
  146. #endif
  147. #endif
  148. }
  149.  
  150.  
  151.  
  152. /*****************************************************************************/
  153.  
  154.  
  155.  
  156. Boolean    CheckMachineList(void) {
  157.     short            v1, v2;
  158.     WindowPtr        theWind    = FrontWindow();
  159.     ControlHandle    theControl = ((WindowPeek)theWind)->controlList;
  160.     Rect            minRect    = {16000, 16000, 16000, 16000};
  161.     ControlHandle    minCtl     = nil;
  162.  
  163.     /* walk through the controls in the Front Window and find the scrollbar for the */
  164.     /* machine list.  If there are no machines listed, then we're happening. */
  165.     /* NOTE!!!! Avert young children's eyes at this point, please!  */
  166.     /* I'm being cheap and sleazy here, and using information about the */
  167.     /* PPC browser dialog (that you can see in MacsBug) itself to do this fast.*/
  168.  
  169.     while(theControl) {
  170.         v1 = (*theControl)->contrlRect.top + (*theControl)->contrlRect.left;
  171.         v2 = minRect.top + minRect.left;
  172.         if (v1 < v2) {
  173.             minRect = (*theControl)->contrlRect;
  174.             minCtl  = theControl;
  175.         }
  176.         theControl = (*theControl)->nextControl;
  177.     }
  178.  
  179.     if (minCtl)
  180.         if ((*minCtl)->contrlMax == -6)
  181.             return(true);
  182.  
  183.      return(false);
  184. }
  185.  
  186.  
  187.  
  188. /*****************************************************************************/
  189.  
  190.  
  191.  
  192. /* here's the workhorse for us */
  193. /* we make the following assumptions */
  194. /* well, only one really....    */
  195. /* the FrontWindow IS the PPC browser! */
  196. /* if this isn't true, then things are too weird for words */
  197.  
  198. void    DoModalFilter(void) {
  199.     if(TickCount() > OurParamBlock.tickCounter) {
  200.         OurParamBlock.tickCounter = TickCount() + kFiveSeconds;
  201.         if(CheckMachineList()) {
  202.             PostEvent(keyDown,kDownArrowKey);
  203.             PostEvent(keyUp,kDownArrowKey);
  204.         }
  205.     }
  206. }
  207.  
  208.  
  209.  
  210. /*****************************************************************************/
  211.  
  212.  
  213.  
  214. ControlHandle    FindSB(WindowPtr theWindow) {
  215.     Ptr                sBarProc, otherProc;
  216.     ControlHandle    theControls, fakeScroll;
  217.     WindowPeek        theWind = (WindowPeek)theWindow;
  218.     Rect            theRect = {0, 0, 9, 9};
  219.  
  220.     fakeScroll = NewControl((WindowPtr)theWind, &theRect, "\p", false, 0, 0, 10, 16, 0);
  221.     sBarProc   = *((*fakeScroll)->contrlDefProc);
  222.     StripAddress(&sBarProc);
  223.     DisposeControl(fakeScroll);
  224.  
  225.     theControls = theWind->controlList;
  226.     while (theControls) {
  227.         /* don't test against my sample */
  228.         if (theControls != fakeScroll) {
  229.             otherProc = *((*theControls)->contrlDefProc);
  230.             StripAddress(&otherProc);
  231.             if (otherProc == sBarProc)
  232.                 return(theControls);
  233.         }
  234.     }
  235.     theControls = (*theControls)->nextControl;
  236.  
  237.     return(nil);
  238. }
  239.  
  240.  
  241.  
  242.